package network.TCP.copy;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-04-05
 * Time:14:43
 */
public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8888);
        Socket socket = serverSocket.accept();
        receivePicture(socket);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        bw.write("收到图片");
        bw.newLine();
        bw.flush();
        socket.shutdownOutput();
        socket.close();
        serverSocket.close();
    }
    public static void receivePicture(Socket socket) throws IOException {
        BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
        FileOutputStream fos = new FileOutputStream("src\\network\\socket\\copy\\picture.png");
        byte[] bytes = bis.readAllBytes();
        fos.write(bytes);
        fos.close();
    }
}
